//
//  HomePeopleMenueSection.swift
//  ProjectApp
//
//  Created by 邹琳 on 2019/7/24.
//  Copyright © 2019 邹琳. All rights reserved.
//

import UIKit

class HomePeopleMenueSection: UIView {
    
    @IBOutlet weak var stackView: UIStackView!
    
    let arr = ["推荐", "女神", "男神", "交友"]
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        self.stackView.arrangedSubviews.forEach { (temp) in
            temp.removeFromSuperview()
        }
        
        for (idx, value) in arr.enumerated() {
            let btn = UIButton(type: .custom)
            btn.setTitleColor(UIColor(0xa8a8a8), for: .normal)
            btn.setTitleColor(UIColor.black, for: .selected)
            btn.titleLabel?.font = UIFont.mediumFont(15)
            btn.setTitle(value, for: .normal)
        	btn.tag = 1000 + idx
            self.stackView.addArrangedSubview(btn)
            btn.addTarget(self, action: #selector(btnAction), for: .touchUpInside)
        }
    }
    
    @objc func btnAction(_ sender: UIButton) {
        self.stackView.arrangedSubviews.forEach { (temp) in
            let btn = temp as! UIButton
            btn.isSelected = false
            btn.titleLabel?.font = UIFont.mediumFont(15)
        }
        
        sender.isSelected = true
        sender.titleLabel?.font = UIFont.mediumFont(19)
    }
    
    static func createFromNib() -> HomePeopleMenueSection? {
        let topLevelArray = Bundle.main.loadNibNamed("HomePeopleMenueSection", owner: self, options: nil)
        let views = Array(topLevelArray!).filter { $0 is HomePeopleMenueSection }
        return views.last as? HomePeopleMenueSection
    }
}
